//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __SLIP_H__
#define __SLIP_H__
////////////////////slip protocal//////////////////////////////
#define SLIP_PACK_MAX_SIZE 1024*3
#define SLIP_END            (unsigned char)192  /* indicates end of packet */
#define SLIP_ESC            (unsigned char)219  /* indicates byte stuffing */
/* SLIP_ESC SLIP_ESC_END means SLIP_END data byte */
#define SLIP_ESC_END        (unsigned char)220
/* SLIP_ESC SLIP_ESC_ESC means SLIP_ESC data byte */
#define SLIP_ESC_ESC        (unsigned char)221

#define SLIP_RECV_SUCCESS       0
#define SLIP_RECV_NODATA        1
#define SLIP_RECV_ERROR         2
////////////////////slip protocal end//////////////////////////

class SLIP : public Driver {
public:
    CARAPI Read(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ UInt32 uNumberOfBytesToRead,
        /* [out] */ EzByteBuf ebbData,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ EzByteBuf ebbData,
        /* [out] */ UInt32 * puNumberOfBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Int32 nControlCode,
        /* [in] */ EzByteBuf ebbInData,
        /* [out] */ EzByteBuf ebbOutData,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();

public:
    ECode Initialize(void);

private:
    void send_char(unsigned char c);
    int recv_char(unsigned char *p);
    int slip_send_packet(UInt8 *p, Int32 len);
    int slip_recv_packet(UInt8 *p, Int32 len);
};
#endif //__SLIP_H__
